import { Action } from "redux";
import { IPost } from "./reducer";

export enum ActTypes {
  Destroy = "[Main] Destroy",
  GetCategoryListAsync = "[Main] GetCategoryList",
  SetCategoryList = "[Main] SetCategoryList",
  SetCategoryActive = "[Main] SetCategoryActive",
  GetPostsAsync = "[Main] GetPostAsync",
  SetPosts = "[Main] SetPosts"
}

export class ActionDestroy implements Action {
  readonly type = ActTypes.Destroy;
}

export class ActionGetCategoryListAsync implements Action {
  readonly type = ActTypes.GetCategoryListAsync;
}

export class ActionSetCategoryList implements Action {
  readonly type = ActTypes.SetCategoryList;

  constructor(public payload: string[]) {}
}

export class ActionSetCategoryActive implements Action {
  readonly type = ActTypes.SetCategoryActive;

  constructor(public payload: string) {}
}

export class ActionGetPostsAsync implements Action {
  public readonly type = ActTypes.GetPostsAsync;

  constructor(public payload: string) {}
}

export class ActionSetPosts implements Action {
  readonly type = ActTypes.SetPosts;

  constructor(
    public payload: {
      [key: string]: IPost[];
    }
  ) {}
}

export type Actions =
  | ActionDestroy
  | ActionGetCategoryListAsync
  | ActionSetCategoryList
  | ActionGetPostsAsync
  | ActionSetPosts
  | ActionSetCategoryActive;
